﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace YRevitJig
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class JigArc : IExternalCommand
	{
		public Result Execute(ExternalCommandData cmdData, ref string message, ElementSet elements)
		{
			UIDocument activeUIDocument = cmdData.Application.ActiveUIDocument;
			ViewAssist.ViewValidating(activeUIDocument.Document, activeUIDocument.ActiveView);
			XArcJig xarcJig = new XArcJig(activeUIDocument);
			XYZ xyz = xarcJig.PickCenterPoint("请确定圆弧中心点：");
			bool flag = xyz == null;
			Result result;
			if (flag)
			{
				xarcJig.Dispose();
				result = Autodesk.Revit.UI.Result.Succeeded;
			}
			else
			{
				XYZ xyz2 = xarcJig.PickStartPoint(xyz, "请确定圆弧起点：");
				bool flag2 = xyz2 == null;
				if (flag2)
				{
					xarcJig.Dispose();
					result = Autodesk.Revit.UI.Result.Succeeded;
				}
				else
				{
					XYZ xyz3 = xarcJig.PickEndPoint(xyz, xyz2, "请确定圆弧终点：");
					bool flag3 = xyz3 == null;
					if (flag3)
					{
						xarcJig.Dispose();
						result = Autodesk.Revit.UI.Result.Succeeded;
					}
					else
					{
						Transaction transaction = new Transaction(activeUIDocument.Document);
						transaction.Start("CreateCurve");
						List<Curve> list = xarcJig.CreateCurves();
						activeUIDocument.Document.Create.NewDetailCurve(activeUIDocument.ActiveView, list[0]);
						transaction.Commit();
						xarcJig.Dispose();
						result = Autodesk.Revit.UI.Result.Succeeded;
					}
				}
			}
			return result;
		}
	}
}
